package com.ruoyi.project.system.domain.dto;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.project.system.domain.BeiDiao.Base;
import lombok.Data;

@Data
public class JudiciaryDto extends Base {

    private Long crc;

    private String casesTree;

    private String count;

    private String preservationCount;

    private String preservationCases;

    private String administrativeCount;

    private String administrativeCases;

    private String civilCount;

    private String civilCases;

    private String implementCount;

    private String implementCases;

    private String criminalCount;

    private String criminalCases;

    private String bankruptCount;

    private String bankruptCases;

    public JudiciaryDto() {
    }

    public JudiciaryDto(String orderNo, String msg, JSONObject data) {
        this.setOrderNo(orderNo);
        this.setStatus("1");
        this.setMsg(msg);

        this.setCrc(data.getLong("crc"));
        this.setCasesTree(data.getJSONObject("cases_tree").toJSONString());
        this.setCount(data.getJSONObject("count").toJSONString());
        if (data.containsKey("administrative")) {
            JSONObject administrative = data.getJSONObject("administrative");
            this.setPreservationCases(administrative.containsKey("cases") ? administrative.getJSONArray("cases").toJSONString() : null);
            this.setPreservationCount(administrative.containsKey("count") ? administrative.getJSONObject("count").toJSONString() : null);
        }
        if (data.containsKey("preservation")) {
            JSONObject preservation = data.getJSONObject("preservation");
            this.setPreservationCases(preservation.containsKey("cases") ? preservation.getJSONArray("cases").toJSONString() : null);
            this.setPreservationCount(preservation.containsKey("count") ? preservation.getJSONObject("count").toJSONString() : null);
        }
        if (data.containsKey("civil")) {
            JSONObject civil = data.getJSONObject("civil");
            this.setCivilCases(civil.containsKey("cases") ? civil.getJSONArray("cases").toJSONString() : null);
            this.setCivilCount(civil.containsKey("count") ? civil.getJSONObject("count").toJSONString() : null);
        }
        if (data.containsKey("implement")) {
            JSONObject implement = data.getJSONObject("implement");
            this.setImplementCases(implement.containsKey("cases") ? implement.getJSONArray("cases").toJSONString() : null);
            this.setImplementCount(implement.containsKey("count") ? implement.getJSONObject("count").toJSONString() : null);
        }
        if (data.containsKey("criminal")) {
            JSONObject criminal = data.getJSONObject("criminal");
            this.setCivilCases(criminal.containsKey("cases") ? criminal.getJSONArray("cases").toJSONString() : null);
            this.setCivilCount(criminal.containsKey("count") ? criminal.getJSONObject("count").toJSONString() : null);
        }
        if (data.containsKey("bankrupt")) {
            JSONObject bankrupt = data.getJSONObject("bankrupt");
            this.setBankruptCases(bankrupt.containsKey("cases") ? bankrupt.getJSONArray("cases").toJSONString() : null);
            this.setBankruptCount(bankrupt.containsKey("count") ? bankrupt.getJSONObject("count").toJSONString() : null);
        }
    }

    public JudiciaryDto(String orderNo, String status, String msg) {
        this.setOrderNo(orderNo);
        this.setStatus(status);
        this.setMsg(msg);
    }

}
